const mongo = require('../db/db.js')
const formidable = require('formidable')
const time = require('../../util/time.js')
const getId = require('../../util/getId.js')
const path = require('path')
const fs = require('fs')
module.exports = {
    addkind:function (req,res) {
        res.setHea
        var form = new formidable.IncomingForm();
        form.uploadDir = __dirname+'../../../static/uploadd'
        form.parse(req,function (err,files,file) {
            if(err){
                res.json({
                    "error" : 1,
                    "message" : "错误信息"
                })
                return
            }

           let extname =  path.extname(file.imgFile.name);
            let mtime = time.tuTime()
            fs.rename(file.imgFile.path,__dirname+'/../../static/upload/'+mtime+extname,function (err) {
                if(err){
                    res.json({
                        "error" : 1,
                        "message" : "错误信息"
                    })
                    return
                }
                let pjname = '/upload/'+mtime+extname;
                res.json({
                    "error" : 0,
                    "url" :pjname
                })

            })
        })
    }
}
